
public class HttpContext {
    public SocketConnection connection {get; private set;}
    public HttpRequest request {get; private set;}
    public HttpResponse response {get; private set;}
    public HttpServer server {get; private set;}

    public static async HttpContext from_client_connection(HttpServer server, SocketConnection connection) throws IOError, HttpProtocolError {
        var context = new HttpContext();
        context.server = server;
        context.connection = connection;
        context.request = yield HttpRequest.parse(context);
        context.response = new HttpResponse(context);
        return context;
    }

    public async void close() {
        yield this.connection.close_async();
    }
    public async void respond(HttpResponseContent content, IStatusCode? statusCode = new StatusCode("OK", 200), string? content_type = "text/html") throws IOError {
        this.response.status_code = statusCode;
        this.response.content_type.value = content_type;
        yield this.response.write(content);
    }
}
